Skip to content

下载文件扩展 - HttpDownloadFileEx

函数简介

下载文件,支持断点续传、进度回调、重试和超时设置。

接口名称

HttpDownloadFileEx

DLL调用

c
int32_t HttpDownloadFileEx(int64_t instance, const char* url, const char* save_path, DownloadCallback callback, int64_t user_data, int32_t max_retries, int32_t connect_timeout_sec, int32_t read_timeout_sec);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
url字符串完整URL
save_path字符串本地保存路径
callbackDownloadCallback下载进度回调函数
user_data长整数型传给callback的用户数据
max_retries整数型断线后最大重试次数
connect_timeout_sec整数型连接超时秒数,0使用默认值
read_timeout_sec整数型读取超时秒数,0使用默认值

回调函数类型定义

c
void DownloadCallback(int64_t current, int64_t total, int64_t speed, int64_t user_data);
参数名类型说明
current长整数型已下载字节数
total长整数型总字节数(0表示未知)
speed长整数型当前下载速度(字节/秒)
user_data长整数型由调用方传入的用户数据

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30);
cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30)
text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.HttpDownloadFileEx(“https://example.com/file.zip“, “D:\\downloads\\file.zip“, nullptr, 0, 3, 10, 30)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.HttpDownloadFileEx("https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
HttpDownloadFileEx(instance, "https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30);
csharp
long instance = CreateCOLAPlugInterFace();
HttpDownloadFileEx(instance, "https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
HttpDownloadFileEx(instance, "https://example.com/file.zip", "D:\\downloads\\file.zip", nullptr, 0, 3, 10, 30)

返回值

整数型,错误码,0表示成功,负数表示失败(错误码与 HttpDownloadFile 一致)。

注意事项

  • 支持断点续传和自动重试
  • 重试次数不包括首次尝试
  • 超时设置为0时使用默认值(通常为30秒)
  • 适合下载大文件或网络不稳定的场景